const Artitalk = require('../../models/artitalk')

module.exports = (req,res) => {
  console.log(req.body);
  const formData = {
    username: req.body.username,
    avatar:req.body.avatar,
    role:req.body.role,
    user_id:req.body.user_id,
    content:req.body.content,
    created_time: new Date,
    last_modified_time:new Date
  }
  new Artitalk(formData).save((err,artitalkDoc) => {
    Artitalk.find((err,newArtitalkDoc) => {
      if (err) {
        res.status(500).json({
          err_code: 500,
          message:err.message
        })
      }
      res.status(200).json({
        err_code: 0,
        data: newArtitalkDoc,
        message:'评论成功'
      })
    })
  })

}